def yolo2bbox(cx, cy, w, h):
    l = cx - w/2
    t = cy - h/2
    r = cx + w/2
    b = cy + h/2
    return l, t, r, b 

def IOU(box1,box2):
    bxmin = max(box1[0],box2[0])
    bymin = max(box1[1],box2[1])
    bxmax = min(box1[2],box2[2])
    bymax = min(box1[3],box2[3])
    bwidth = bxmax-bxmin
    bhight = bymax-bymin
    if bwidth  <= 0 or bhight <= 0:
        return 0
    inter = bwidth*bhight
    union = (box1[2]-box1[0])*(box1[3]-box1[1])+(box2[2]-box2[0])*(box2[3]-box2[1])-inter
    return inter/union